var windowName = "myContactAdd";
var Page;
apiready = function(){
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        name:""
        ,phone:""
    },{
        //页面方法
        "init":function () {
            var data = getData4Page();
            var id = data.id;
            this.id = id
            log(id,"id_:")
            if (isTrue(id)) {
                getData();
            }
        },
        submit: function () {
            if (!isTrue(this.name)){showToast("请输入称谓");return;}
            if (!isTrue(this.phone)){showToast("请输入联系人电话");return;}
            var data= {
                name:this.name,
                phone:this.phone
            };
            if (isTrue(this.id)) {
                data.id = this.id
            }
            apiPost("/api/userContacts", data, function (res, code) {
                if (code == 200) {
                    showToast(res.message);
                    gobackDelay()
                }else {
                    showToast(res.message);
                }
            });

        }
    })
    Page.init()
}
function getData() {
    apiGet("/api/userContacts/" + Page.id, {}, function (res, code) {
        if (code == 200) {
            Page.id=res.data.id;
            Page.name=res.data.name;
            Page.phone=res.data.phone;
        }else {
        }
        logJson(res,"/app/my/address_: ");
    });
}